package chapter06;

import java.util.concurrent.TimeUnit;

/**
 * @author chisheng
 * @since 2021-11-11
 */
public class ThreadGroupInterrupt {

    public static void main(String[] args) throws InterruptedException {
        ThreadGroup myGroup = new ThreadGroup("myGroup");
        new Thread(myGroup, () -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    break;
                }
            }
            System.out.println("T1 will exit.");
        }).start();
        new Thread(myGroup, () -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    break;
                }
            }
            System.out.println("T2 will exit.");
        }).start();

        TimeUnit.MILLISECONDS.sleep(2);
        myGroup.interrupt();
    }

}
